<?php
/*
 * Plugin Name: GetIt
 * Plugin URI: -----
 * Description: This plugin is a mod of the press-this tool.  It is created as a plugin so updates to wordpress do not lose changes.
 * Mods include formatting the post, simplifying entry and allowing easier installation into browsers.
 * Version: 1.0
 * Author: Mark Tilly
 * Author URL: http://www.memeposts.com
 * License: GPLv2 or later
/*
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/

//Activation hook
register_activation_hook(__FILE__, 'mct_get_activehook');
//Set up menu
add_action('admin_menu','mct_get_addmenu');

function mct_get_activehook(){
    return;
}

function mct_get_addmenu(){
    add_options_page('GetIt','Get It','edit_posts',basename(__FILE__),'mct_get_options_page');
}

function mct_get_options_page(){
    require_once('./admin.php');

    $title = 'Get It';

    require_once('./admin-header.php');

    ?>
    <div class="wrap">
    <?php screen_icon('tools'); ?>
    <h2><?php echo esc_html( $title ); ?></h2>

    <?php if ( current_user_can('edit_posts') ) : ?>
    <div class="tool-box">
            <p><?php _e('Get It is a bookmarklet: a little app that runs in your browser and lets you grab bits of the web.');?></p>

            <p><?php _e('Use Get It to clip text, images and videos from any web page. Then edit and add more straight from Get It before you save or publish it in a post on your site.'); ?></p>
            <h3>PC/Mac Instructions</h3>
            <p class="description"><?php _e('Drag-and-drop the following link to your bookmarks bar') ?></p>
            <p class="pressthis"><a onclick="return false;" href="<?php echo htmlspecialchars( get_js_code() ); ?>"><span><?php _e('Get It') ?></span></a></p>
            <div class="pressthis-code" >
            <p class="description"><?php _e('If your bookmarks toolbar is hidden or your browser does not allow you to drag and drop the link then:') ?></p>
            <p class="description"><?php _e('Highlight the Bookmark code in the box below then Ctrl-c/Command-c to copy the code. Open your Bookmarks/Favorites manager and create a new bookmark/favorite. Edit the name to Get It and save.  
                Click Manage/Organize Bookmarks/Favorites and edit the Get It entry you just created.  Paste the code into the URL/Location/Address field using Ctrl-v/Command-v.
                Save the entry') ?></p>
            <p><textarea rows="5" cols="120" ><?php echo htmlspecialchars( get_js_code() ); ?></textarea></p>
            <h3>iPhone or iPad Instructions</h3>
            <p class="description"><?php _e('Touch the code box above once (keyboard appears) then touch and hold until the magnifier 
                appears and choose Select All then Copy.  
                Add a Bookmark and set the title to Get It then save.  Now touch the bookmarks option again and choose Edit bookmarks from the top right.
                and select the Get It bookmark you just created.
                Touch the location box then the x and remove the old location.  Now Touch and Paste your previous copy into the bookmark.  
                Press the Bookmarks button at the top to finish editing and then touch done in the upper right.') ?></p>
            <h3>Android Phone/Tablet Instructions</h3>
            <p class="description"><?php _e('Touch the code box above until the Edit Text menu appears, 
                choose Copy All.  Touch the menu and choose Add Bookmark.  Edit the title to Get It then touch the Location box 
                until the Edit Text menu appears.  Choose Paste then Done to save the bookmark') ?></p>
            <h3><?php _e('Once you have saved the bookmark, whenever you are on a web page that you would like to save and post
                just press the Get It bookmark, add any text, categories and tags, then click Publish and you are done!') ?></h3>
            </div>
    </div>
    <?php
    endif;
}

function get_js_code(){
    $link = "javascript:
var d=document,
w=window,
e=w.getSelection,
k=d.getSelection,
x=d.selection,
s=(e?e():(k)?k():(x?x.createRange().text:0)),
f='" . plugins_url('GetIt/get-it.php') . "',
l=d.location,
e=encodeURIComponent,
u=f+'?u='+e(l.href)+'&t='+e(d.title)+'&s='+e(s)+'&v=4';
a=function(){if(!w.open(u,'t','toolbar=0,resizable=1,scrollbars=1,status=1,width=720,height=570'))l.href=u;};
if (/Firefox/.test(navigator.userAgent)) setTimeout(a, 0); else a();
void(0)";

    $link = str_replace(array("\r", "\n", "\t"),  '', $link);

    return $link;    
}
?>